import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        char[] ch = new char[]{'a', 'b', 'c'};
        String s1 = new String(ch);      // s1对象并不在常量池中
         s1.intern();                   // s1.intern(); 调用之后，会将s1对象的引用放入到常量池中
        String s2 = "abc";               // "abc" 在常量池中存在了，s2创建时直接用常量池中的"abc"的引用
        System.out.println(s1 == s2);
    }

    public static void main21(String[] args) {
        String s1="abc";
        String s2="abc";
        String s3=new String("abc");
        String s4=new String("abc");
        System.out.println(s1 == s2);
        System.out.println(s3 == s4);
        System.out.println(s1 == s3);
    }
    public static void main20(String[] args) {
        String s = "Hello World";
        System.out.println(s.endsWith("ld"));    // 输出 true
        System.out.println(s.startsWith("He"));  // 输出 true
    }
    public static void main19(String[] args) {
        String str = "   hello  world   ";
        System.out.println("[" + str + "]");          // 输出 "[   hello  world   ]"
        System.out.println("[" + str.trim() + "]");   // 输出 "[hello  world]"
    }
    public static void main18(String[] args) {
        String str = "HelloWorld";
        String s = str.substring(5);
        String s1 = str.substring(1, 7);
        System.out.println(s);   // 输出 "World"
        System.out.println(s1);  // 输出 "elloWo"
    }
    public static void main17(String[] args) {
        String str = "Spring&Summer&Autumn&Winter";
        String[] strings = str.split("&");
        System.out.println(Arrays.toString(strings));  // 输出 ["Spring", "Summer", "Autumn", "Winter"]

        for (String s : strings) {
            System.out.println(s);
        }

        String[] strings1 = str.split("&", 2);
        System.out.println("限制分割次数: " + Arrays.toString(strings1));  // 输出 ["Spring", "Summer&Autumn&Winter"]

        String str1 = "202.507.031";
        String[] strings2 = str1.split("\\.");
        System.out.println("拆分特殊的分割: " + Arrays.toString(strings2));  // 输出 ["202", "507", "031"]

        String s = "Spring&Summer/Autumn&Winter";
        String[] strings3 = s.split("&|/");
        System.out.println("多次拆分: " + Arrays.toString(strings3));  // 输出 ["Spring", "Summer", "Autumn", "Winter"]
    }
    public static void main16(String[] args) {
        String s = "aaabbbcccddd";
        System.out.println("字符的替换: " + s.replace('a', 'A'));  // 输出 "AAAbbbcccddd"
        System.out.println("字符串的替换: " + s.replace("aaa", "AAA"));  // 输出 "AAAbbbcccddd"
        System.out.println("从第一个字符串开始替换: " + s.replaceFirst("aaa", "ccc"));  // 输出 "cccbbbcccddd"

        String s1 = "aaacccbbbaaaccc";
        System.out.println("所有字符串替换: " + s1.replaceAll("aaaccc", "dddeee"));  // 输出 "dddeeebbbdddeee"
    }
    public static void main15(String[] args) {
        String s = String.format("%d-%d-%d", 2025, 11, 22);
        System.out.println(s);  // 输出 "2025-11-22"

        String s1 = String.format("%d/%d/%d", 2025, 11, 22);
        System.out.println(s1); // 输出 "2025/11/22"
    }
    public static void main14(String[] args) {
        String str = "HelloWorld!";
        char[] chars = str.toCharArray();
        System.out.println("调用方法打印字符数组: " + Arrays.toString(chars));
        // 输出: 调用方法打印字符数组: [H, e, l, l, o, W, o, r, l, d, !]

        System.out.println("for循环打印字符数组：");
        for (int i = 0; i < chars.length; i++) {
            System.out.print(chars[i]);
        }
        // 输出: HelloWorld!

        System.out.println("\n数组转字符串：");
        String str1 = new String(chars);
        System.out.println(str1);  // 输出 "HelloWorld!"
    }
    public static void main12(String[] args) {
        String str = "hello";
        System.out.println(str.toUpperCase());  // 输出 "HELLO"

        String str1 = "helloWorld";
        System.out.println(str1.toUpperCase()); // 输出 "HELLOWORLD"

        String str2 = "HELLO";
        System.out.println(str2.toLowerCase()); // 输出 "hello"

        String str3 = "HELLOWorld";
        System.out.println(str3.toLowerCase()); // 输出 "helloworld"
    }
    public static void main11(String[] args) {
        // 字符串转数字
        String str = "12345";
        int i = Integer.parseInt(str);
        int i1 = Integer.valueOf(str);
        System.out.println(i);   // 输出 12345
        System.out.println(i1);  // 输出 12345

        String str1 = "12.34";
        double d = Double.parseDouble(str1);
        double d1 = Double.valueOf(str1);
        System.out.println(d);   // 输出 12.34
        System.out.println(d1);  // 输出 12.34

        // 数字转字符串
        int i2 = 112233;
        String str2 = String.valueOf(i2);
        System.out.println(str2);  // 输出 "112233"

        double d2 = 11.2233;
        String str3 = String.valueOf(d2);
        System.out.println(str3);  // 输出 "11.2233"
    }
    public static void main10(String[] args) {
        String s = "hellohello";
        System.out.println(s.lastIndexOf('h'));     // 输出 5
        System.out.println(s.lastIndexOf("loh"));   // 输出 -1
        System.out.println(s.lastIndexOf("ohell")); // 输出 2
        System.out.println(s.lastIndexOf('o', 3));  // 输出 2
        System.out.println(s.lastIndexOf("ell", 5));// 输出 0
    }
    public static void main9(String[] args) {
        String s = "HelloWorld";
        System.out.println(s.indexOf('W'));        // 输出 5
        System.out.println(s.indexOf("ll"));       // 输出 2
        System.out.println(s.indexOf('o', 6));     // 输出 7
        System.out.println(s.indexOf("ello", 7));  // 输出 -1
    }

    public static void main8(String[] args) {
        String s = "hello";
        for (int i = 0; i < s.length(); i++) {
            System.out.println(s.charAt(i));
        }
    }
    public static void main7(String[] args) {
        String s1 = "Hello";
        String s2 = "hello";
        System.out.println(s1.compareToIgnoreCase(s2));  // 输出 0
    }
    public static void main6(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("ac");
        String s3 = new String("abc");
        String s4 = new String("abcdef");

        System.out.println(s1.compareTo(s2));   // 输出 -1
        System.out.println(s1.compareTo(s3));   // 输出 0
        System.out.println(s1.compareTo(s4));   // 输出 -3
    }
    public static void main5(String[] args) {
        String s1 = "abc";
        String s2 = "xyz";
        System.out.println(s1.equals(s2));  // 输出 false

        String s3 = "abc";
        String s4 = "abc";
        System.out.println(s3.equals(s4));  // 输出 true
    }
    public static void main4(String[] args) {
        String s1 = "H";
        String s2 = "H";
        System.out.println(s1 == s2);  // 输出 true

        String s3 = "Hello";
        String s4 = "World";
        System.out.println(s3 == s4);  // 输出 false
    }
    public static void main3(String[] args) {
        char[] chars = {'h', 'e', 'l', 'l', 'o', ',', 'w', 'o', 'r', 'l', 'd'};
        String str2 = new String(chars);
        System.out.println(str2);
    }
    public static void main2(String[] args) {
        String str1 = new String("World");
        System.out.println(str1);
    }
    public static void main1(String[] args) {
        String str = "Hello";
        System.out.println(str);
    }
}
